#include "stdafx.h"
#include "wf_toolregeneratedimensions.h"

#include "pf_information.h"
#include "pf_dimension.h"



WF_ToolRegenerateDimensions::WF_ToolRegenerateDimensions(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_ActionInterface("Tool Regen Dim",
                    container, graphicView) {}


QAction* WF_ToolRegenerateDimensions::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
/*      QAction* action = new QAction(tr("Regenerate Dimension Entities"),
                                  tr("&Regenerate Dimension Entities"),
                                  QKeySequence(), NULL); */
    QAction* action = new QAction(tr("Regenerate Dimension Entities"), NULL);
    //action->zetStatusTip(tr("Regenerates all Dimension Entities"));

    return action;
}

void WF_ToolRegenerateDimensions::init(int status) {
    PF_ActionInterface::init(status);

    trigger();
}



void WF_ToolRegenerateDimensions::trigger() {

    PF_DEBUG->print("PF_ActionToolRegenerateDimensions::trigger()");

    int num = 0;
    for (PF_Entity* e = container->firstEntity(LX_Define::ResolveNone);
            e != NULL;
            e = container->nextEntity(LX_Define::ResolveNone)) {

        if (PF_Information::isDimension(e->rtti()) && e->isVisible()) {
			num++;
			if (((PF_Dimension*)e)->getLabel()==";;") {
				((PF_Dimension*)e)->setLabel("");
			}
            ((PF_Dimension*)e)->update(true);
        }
    }

    if (num>0) {
    	graphicView->redraw();
        PF_DIALOGFACTORY->commandMessage(
            tr("Regenerated %1 dimension entities").arg(num));
    } else {
        PF_DIALOGFACTORY->commandMessage(tr("No dimension entities found"));
    }

    finish();
}


// EOF
